﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Sustainalytics.ScreeningTool.Service.Tests
{
    [TestClass()]
    public class RunControllerTests
    {

        ////see CompanyScreeningControllerTests.RunSelectedCriteria
        //[TestMethod]
        //public void WhenPutMethod_isCalled_RunSelectedCriteriaIsExecuted()
        //{
        //    var sentFilterId = Guid.NewGuid();
        //    var receivedFilterId = Guid.Empty;
        //    var savedResultOutput = new List<ResultOutput>();
        //    var companyScreeningService = new Sustainalytics.ScreeningTool.BL.Fakes.StubICompanyScreening()
        //    {
                
        //        RunSelectedCriteriaGuidGuidBoolean = (filterId, isExport, hasPortfolio) =>
        //        {
        //            receivedFilterId = filterId;
        //            List<ResultOutput> resultOutput = new List<ResultOutput>();
        //            resultOutput.Add(new ResultOutput()
        //            {
        //                CompanyId = Guid.NewGuid(),
        //                CompanyName = "TestCompany1",
        //                Ticker = "12093",
        //                Exchange = "Thamse",
        //                FilterId = filterId,
        //                Id = Guid.NewGuid(),
        //                IsValid = true,
        //                Criteria = new List<CriteriaResultOutput>() 
        //                { 
        //                    new CriteriaResultOutput() { Name = "Ticker", NumericValue = 0, StringValue = "12093", ValueType = CriteriaValueType.String, IsValid = true }, 
        //                    new CriteriaResultOutput() { Name = "CompanyName", NumericValue = 0, StringValue = "TestCompany1", ValueType = CriteriaValueType.String, IsValid = true }, 
        //                    new CriteriaResultOutput() { Name = "TotalEmployee", NumericValue = 15000, StringValue = string.Empty, ValueType = CriteriaValueType.Numeric, IsValid = true }, 
        //                }
        //            });

        //            resultOutput.Add(new ResultOutput()
        //            {
        //                CompanyId = Guid.NewGuid(),
        //                CompanyName = "TestCompany2",
        //                FilterId = filterId,
        //                Exchange = "SomeExchange",
        //                Ticker = "12354",
        //                Id = Guid.NewGuid(),
        //                Criteria = new List<CriteriaResultOutput>()
        //                {
        //                    new CriteriaResultOutput() { Name = "Ticker", NumericValue = 0, StringValue = "12093", ValueType = CriteriaValueType.String, IsValid = false }, 
        //                    new CriteriaResultOutput() { Name = "CompanyName", NumericValue = 0, StringValue = "TestCompany1", ValueType = CriteriaValueType.String, IsValid = false }, 
        //                    new CriteriaResultOutput() { Name = "TotalEmployee", NumericValue = 12000, StringValue = string.Empty, ValueType = CriteriaValueType.Numeric, IsValid = true }, 
        //                }
        //            });
        //            resultOutput.Add(new ResultOutput()
        //            {
        //                CompanyId = Guid.NewGuid(),
        //                CompanyName = "TestCompany3",
        //                FilterId = filterId,
        //                Exchange = "SomeExchange3",
        //                Ticker = "3554",
        //                Id = Guid.NewGuid(),
        //                Criteria = new List<CriteriaResultOutput>()
        //                {
        //                    new CriteriaResultOutput() { Name = "Ticker", NumericValue = 0, StringValue = "12093", ValueType = CriteriaValueType.String, IsValid = false }, 
        //                    new CriteriaResultOutput() { Name = "CompanyName", NumericValue = 0, StringValue = "TestCompany1", ValueType = CriteriaValueType.String, IsValid = false }, 
        //                    new CriteriaResultOutput() { Name = "TotalEmployee", NumericValue = 25000, StringValue = string.Empty, ValueType = CriteriaValueType.Numeric, IsValid = false }, 
        //                }
        //            });

        //            savedResultOutput = resultOutput;
        //        }
        //    };

        //    var runController = Utils.setupController(new RunsController(companyScreeningService));
        //    var createDto = new RunDto { FilterId = sentFilterId };
        //    var response = runController.Put(sentFilterId, createDto);

        //    var result = savedResultOutput;

        //    Assert.AreEqual(receivedFilterId, sentFilterId, "The filter sent is different than the expected one.");
        //    Assert.AreEqual(3, result.Count, "The number of results is different than the expected one.");
        //    Assert.IsTrue(result.All(r => r.Criteria.Count == 3), "The number of criteria is different the expected one.");
        //    Assert.AreEqual(1, result.Where(r => r.IsValid).Count(), "The number of valid results is different than the expected one.");

        //    Assert.IsTrue(response.AreExpected(HttpStatusCode.OK, createDto), "The httpResponse is not as expected.");
        //}

        //[TestMethod]
        //public void WhenPutMethod_isCalled_with_Null_BadRequestIsReturned()
        //{
        //    var companyScreeningService = new Sustainalytics.ScreeningTool.BL.Fakes.StubICompanyScreening();
                        

        //    var runController = Utils.setupController(new RunsController(companyScreeningService));
        //    var response = runController.Put(Guid.Empty, null);


        //    Assert.IsNotNull(response, "returned response should not be null");
        //    Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode, "The response  StatusCode is not BadRequest as expected.");

        //    var expectedPartialResult = new { ErrorStatusCode = ScreeningToolErrorCodesEnum.CreateRunInvalidFilter };
        //    Assert.IsTrue(response.AreExpectedByProperties(expectedPartialResult, er => er.ErrorStatusCode), "The httpResponse is not as expected.");
        //}

        //[TestMethod]
        //public void WhenPutMethod_isCalled_with_EmptyFilterId_BadRequestIsReturned()
        //{
        //    var companyScreeningService = new Sustainalytics.ScreeningTool.BL.Fakes.StubICompanyScreening();

        //    var filterId = Guid.Empty;
        //    var runController = Utils.setupController(new RunsController(companyScreeningService));
        //    var response = runController.Put(filterId, new RunDto {  FilterId = filterId });

        //    Assert.IsNotNull(response, "returned response should not be null");
        //    Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode, "The response  StatusCode is not BadRequest as expected.");

        //    var expectedPartialResult = new { ErrorStatusCode = ScreeningToolErrorCodesEnum.CreateRunInvalidFilter };
        //    Assert.IsTrue(response.AreExpectedByProperties(expectedPartialResult, er => er.ErrorStatusCode), "The httpResponse is not as expected.");
        //}


        //[TestMethod]
        //public void WhenDeleteMethod_isCalled_the_RunResultsAreCleared()
        //{
        //    Guid? clearedResultsFilterId = null;
        //    var companyScreeningService = new Sustainalytics.ScreeningTool.BL.Fakes.StubICompanyScreening()
        //    {
        //        ClearResultOutputGuid = (id) =>
        //        {
        //            clearedResultsFilterId = id;
        //        }
        //    };

        //    var filterId = Guid.NewGuid();
        //    var runController = Utils.setupController(new RunsController(companyScreeningService));
        //    var response = runController.Delete(filterId);

        //    Assert.IsNotNull(response, "returned response should not be null");
        //    Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The response  StatusCode is not Ok as expected.");

        //    var expectedPartialResult = new { ErrorStatusCode = ScreeningToolErrorCodesEnum.CreateRunInvalidFilter };
        //    Assert.AreEqual(clearedResultsFilterId, filterId, "cleared run results not called");
        //}
    }
}
